package com.bw.flinkstreaming.source.bw1;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.ArrayList;

/**
 * 需求：自定义不带并行度的数据源，没有并行度表示并行度就是1
 *
 * */
public class ParallelSourceTest {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<Long> longDataStreamSource = env.addSource(new ParallelSource()).setParallelism(2);
        SingleOutputStreamOperator<Long> result = longDataStreamSource.filter(new FilterFunction<Long>() {
            @Override
            public boolean filter(Long value) throws Exception {
                return value % 2 == 0;
            }
        });
        result.print().setParallelism(1);
        env.execute("ParallelSourceTest");
    }
}
